<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <!-- <link rel="stylesheet" type="text/css" href="../css/aui.css" /> -->
</head>
<style>
    .aui-radio-name {
        height: 26px;
        line-height: 26px;
        margin: 8px 10px 8px -5px;
        float: left;
    }

    /*单选、多选*/
    .aui-radio {
        width: 26px;
        height: 26px;
        position: relative;
        margin: 8px 10px;
        background: #ffffff;
        border: solid 1px #dddddd;
        border-radius: 50%;
        display: table;
        float: left;
        -webkit-appearance: none;
        transition: background-color ease 0.1s;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            扫码采集
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">当前操作人:</div>
                    <input type="text" class="aui-input" id="empName" value="" disabled style="width: 80%;" />
                    <i class="aui-btn aui-btn-info aui-input-addon aui-iconfont" onclick="takeQuitPostClick()">上岗</i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">合格:</div>
                    <div class="aui-list-item-label" id="quantityQty" style="width: 10%;"></div>
                    <div class="aui-list-item-label">不良:</div>
                    <div class="aui-list-item-label" id="unQuantityQty"></div>
                    <div class="aui-list-item-label">返修:</div>
                    <div class="aui-list-item-label" id="repairQTy"></div>
                    <i class="aui-btn aui-btn-info aui-input-addon aui-iconfont" onclick="clearRecord()">清空</i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width:200px;">条码扫描区:</div>
                    <input type="text" class="aui-input" placeholder="请扫描条码" id="boxnum" onclick="getIdSelector();"
                        onfocus="focusFn(this)">
                </div>
                <div class="aui-list-item-label">关键件:</div>
                <div class="aui-list-item-label" id="kpartBarcode"></div>
            </li>
        </ul>
        <!-- margin-top:3%; -->
        <div style=" height: 100%;width: 100%;display:none;margin-bottom:50px;" id="tableDiv">
            <table class="table"
                style='background-color:#F8F8F8 ;width:100%; font-size:14px;color:#03a9f4;border:solid 1px #FFFFFF;table-layout:fixed'
                id="table">
                <thead>
                    <tr>
                        <td style="width:43%;text-align:center;">父件条码</td>

                        <td style="width:33%;text-align:center;">产品名称</td>

                        <td style="width:24%;text-align:center;">采集时间</td>
                    </tr>
                </thead>
                <tbody id="tbodytable">
                </tbody>
            </table>
        </div>
        <!-- border:solid 1px #FFFFFF; -->
        <div style=" height: 100%;width: 100%;margin-top:3%;display:none;margin-bottom:50px;" id="keyParttableDiv">
            <table class="table"
                style='background-color:#F8F8F8;width:100%; font-size:14px;color:#03a9f4;border:solid 1px #FFFFFF;table-layout:fixed'
                id="keyParttable">
                <thead>
                    <tr>
                        <td style="width:10%;text-align:center;">序号</td>

                        <td style="width:20%;text-align:center;">零件号</td>

                        <td style="width:30%;text-align:center;">关键件条码</td>

                        <td style="width:20%;text-align:center;">采集时间</td>

                        <td style="width:20%;text-align:center;">操作</td>
                    </tr>
                </thead>
                <tbody id="keyParttbodytable">
                </tbody>
            </table>
        </div>

        <div class="aui-content aui-margin-b-15" style="margin-top:100px;display: none;" id="flagZhDiv">
            <div class="aui-content">
                <div style="height:150px;
                display: flex;
                align-items: center;
                justify-content: center;margin: 0 auto;
                font-size: 35px;
                background-color: darkgray;
                color: white;
                text-align: justify;">第一次</div>
            </div>
        </div>

        <div class="aui-content aui-margin-b-15" style="margin-top:50px;display: none;" id="citemDiv">
            <div id="citemList" class="aui-content">
                <div class="aui-form">
                    检测项内容
                </div>
                <div class="aui-form" id="citemForm">

                </div>
            </div>
        </div>

        <div style="width:100%;margin-top:2%;"></div>

    </div>
    <!-- <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer> -->
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";   //设备唯一号
    var workCenterCode = "";  //生产线编码
    var workCellCode = "";    //工位编码
    var opCode = "";          //工序编码
    var ruleCode = "";          //条码规则
    var scancodeWeb = "";
    var teamCode = "";        //班组编码
    var teamName = "";        //班组名称
    var shiftCode = "";       //班次编码
    var shiftName = "";       //班次名称
    var proddate = "";        //生产日期
    var barcode_type = "";   //条码标识
    var empName = "";  //上岗人员 信息
    var AirTightness = "";//缺陷内容下拉选
    var scanCode = "";   //
    var chkbilldetailsId = "";
    var pageParam = {};
    var flag = "";
    var scanQualifiedCode = "";   //控制扫码后合格不合格按钮显示隐藏

    var isCheckPersonnelSkill = "";//是否开启人员上岗技能校验


    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //初始化查询仓库下拉框
    apiready = function () {

        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        $("#boxnum").focus();
        idSelector = "boxnum";
        //检测内容显示，暂时隐藏
        //$("#itemtableDiv").css('display', 'block');
        //1:查询产线工序信息
        searchWorkCenterData();

    }

    //查询产线工位信息
    function searchWorkCenterData() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getOpCodeByUniCode";
        var data = {
            values: {
                clientCode: equipUniqueId,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                if (myobj.code == 0) {

                    //标题
                    document.getElementById("title").innerHTML = myobj.opCode + "扫码采集";
                    workCenterCode = myobj.workCenterCode;
                    workCellCode = myobj.workCellCode;
                    opCode = myobj.opCode;
                    ruleCode = myobj.ruleCode;
                    barcode_type = myobj.barcode_type;
                    isCheckPersonnelSkill = myobj.isCheckPersonnelSkill;
                    AirTightness = myobj.AirTightness;
                    if (myobj.scanQualifiedCode != null) {
                        scanQualifiedCode = myobj.scanQualifiedCode;
                    }


                    if (opCode != null && opCode != "") {

                        //1:查询当前操作人员信息
                        searchDutyPersonData();


                    }

                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //查询人员信息
    function searchDutyPersonData() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getProductionAssemblyTake";
        var data = {
            values: {
                workCenterCode: workCenterCode,
                opCode: opCode,
                workCellCode: workCellCode,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                if (myobj.code == 0) {
                    // document.getElementById("empName").innerHTML = myobj.empName;
                    empName = myobj.empName;
                    $("#empName").val(myobj.empName);
                    document.getElementById("kpartBarcode").innerHTML = myobj.count;

                    teamCode = myobj.teamCode;
                    teamName = myobj.teamName;
                    shiftCode = myobj.shiftCode;
                    shiftName = myobj.shiftName;
                    proddate = myobj.proddate;

                    if (myobj.zc != null && myobj.zc != "") {
                        var list = eval(myobj.zc);
                        var html = "";
                        for (var i = 0; i < list.length; i++) {
                            scancodeWeb = list[i].produ_barcode;
                            html += "<tr style='text-align:center;color:#0099FF'>";
                            html += "<td  style='word-wrap:break-word;word-break:break-all;'>" + list[i].produ_barcode + "</td>";
                            if (list[i].produ_name != 'null' && list[i].produ_name != null) {
                                html += "<td style='word-wrap:break-word;word-break:break-all;'>" + list[i].produ_name + "</td>";
                            } else {
                                html += "<td style='word-wrap:break-word;word-break:break-all;'>" + "</td>";
                            }
                            html += "<td style='word-wrap:break-word;word-break:break-all;'>" + list[i].create_date + "</td>";
                            html += "</tr>"
                        }

                        $api.html($api.byId("tbodytable"), html);
                        $("#tableDiv").css('display', 'block');
                    }
                    if (myobj.parts != null && myobj.parts != "") {
                        var list = eval(myobj.parts);
                        var html = "";
                        for (var i = 0; i < list.length; i++) {
                            var kpartBarcode = list[i].kpartBarcode == null ? "" : list[i].kpartBarcode;
                            html += "<tr style='text-align:center;color:#0099FF'>";
                            html += "<td style='word-wrap:break-word;word-break:break-all;'>" + (i + 1) + "</td>";
                            html += "<td style='word-wrap:break-word;word-break:break-all;'>" + list[i].kpartMrlcode + "</td>";
                            html += "<td style='word-wrap:break-word;word-break:break-all;'>" + kpartBarcode + "</td>";
                            if (list[i].kpartBindingTime == null || list[i].kpartBindingTime == 'null') {
                                html += "<td style='word-wrap:break-word;word-break:break-all;'>" + "</td>";
                            } else {
                                html += "<td style='word-wrap:break-word;word-break:break-all;'>" + list[i].kpartBindingTime + "</td>";
                            }
                            html += "<td>" + "<button style = 'background-color:#46A3FF;color:#FFFFFF; onclick='unbind(\"" + list[i].sysid + "\")'>解绑</button>" + "</td>";
                            html += "</tr>"
                        }

                        $api.html($api.byId("keyParttbodytable"), html);

                        $("#keyParttableDiv").css('display', 'block');
                    }

                } else {
                    // api.toast({
                    //     msg: myobj.msg,
                    //     duration: 3000
                    // });

                    //清空人员信息
                    clear();
                }

                //查询过点
                getPassPoint();

                //5:构造参数
                createPageParam();
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //查询过点
    function getPassPoint() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getPassPoint";

        var operator = $("#empName").val();
        var data = {
            values: {
                lineCode: workCenterCode,
                stationCode: workCellCode,
                opCode: opCode,
                epUniquecode: equipUniqueId,
                operator: operator,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                if (myobj.code == 0) {

                    //合格数
                    document.getElementById("quantityQty").innerHTML = myobj.qualifyQTy;
                    //不合格数
                    document.getElementById("unQuantityQty").innerHTML = myobj.unQualifyQTy;
                    //返修数数
                    document.getElementById("repairQTy").innerHTML = myobj.repairQTy;
                    searchShiftInspection()
                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //开班点检校验
    function searchShiftInspection() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchShiftInspection";

        var data = {
            values: {
                epUniquecode: equipUniqueId,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                flag = myobj.flag;
                console.log(myobj.code);
                if (myobj.code == 0) {

                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //清空过点
    function clearRecord() {
        if (opCode == null || opCode == "" || opCode == undefined) {
            api.toast({
                msg: "唯一号【" + equipUniqueId + "】未配置工序信息",
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/clearPassPoint";
        var data = {
            values: {
                lineCode: workCenterCode,
                stationCode: workCellCode,
                epUniquecode: equipUniqueId,
                opCode: opCode,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                if (myobj.code == 0) {

                    //刷新过点数据显示
                    getPassPoint();

                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //上岗
    function takeQuitPostClick() {
        if (opCode == null || opCode == "" || opCode == undefined) {
            api.toast({
                msg: "唯一号【" + equipUniqueId + "】未配置工序信息",
                duration: 3000
            });
            return;
        }
        api.openWin({
            name: "productionSglg",
            url: 'productionSglg.html',
            pageParam: pageParam,
        });
    }

    //发货单监听回车事件
    $("#boxnum").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {

            $("#boxnum").blur();
            doSearch(tm, scancodeWeb);

        }
    });

    function focusFn(ele) {
        $api.attr(ele, 'readonly', 'readonly');
        setTimeout(() => {
            $api.removeAttr(ele, 'readonly');
        }, 200);
    };

    //条码扫描
    function doSearch(tm, scancode_Web) {

        if (opCode == null || opCode == "" || opCode == undefined) {
            api.toast({
                msg: "唯一号【" + equipUniqueId + "】未配置工序信息,不允许操作",
                duration: 3000
            });
            return;
        }
        if (empName == null || empName == "" || empName == undefined) {
            api.toast({
                msg: "未上岗,不允许操作",
                duration: 3000
            });
            return;
        }
        if (flag === 'N') {
            api.toast({
                msg: "未开班点检,不允许操作",
                duration: 3000
            });
            return;
        }

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/scannerNew";
        var data = {
            values: {
                equipUniqueCode: equipUniqueId,//设备唯一号
                lineCode: workCenterCode,//产线
                workCellCode: workCellCode,//工位
                scanCode: tm,//扫码条码
                opCode: opCode,//工序
                scancodeWeb: scancode_Web,//界面条码
                ruleCode: ruleCode,//条码规则
                un: un,//用户
                shiftCode: shiftCode,//班次
                proddate: proddate,//日期
                barcode_type: barcode_type,//条码类型（1-唯一件，2-批次件
                empName: empName,  //上岗人员
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                $("#boxnum").val("");
                api.setFocus({
                    inputId: 'boxnum',
                    focus: true
                })
                idSelector = "boxnum";
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == 0) {

                    var refresh = myobj.refresh;
                    if (refresh == 'Y') {
                        console.log("Y");

                        document.getElementById("kpartBarcode").innerHTML = myobj.count;
                        //走刷新界面
                        var html = "";

                        scancodeWeb = myobj.barcode;
                        if (scancodeWeb != null && scancodeWeb != '') {
                            html += "<tr style='text-align:center;color:#0099FF;'>";
                            html += "<td style='word-wrap:break-word;word-break:break-all;'>" + scancodeWeb + "</td>";
                            html += "<td style='word-wrap:break-word;word-break:break-all;'>" + myobj.mrlname + "</td>";
                            html += "<td style='word-wrap:break-word;word-break:break-all;'>" + myobj.create_date + "</td>";
                            html += "</tr>"
                        }

                        $api.html($api.byId("tbodytable"), html);

                        $("#tableDiv").css('display', 'block');

                        var html = "";

                        if (myobj.parts != null && myobj.parts != "") {
                            var list = eval(myobj.parts);

                            for (var i = 0; i < list.length; i++) {
                                var kpartBarcode = list[i].kpartBarcode == null ? "" : list[i].kpartBarcode;
                                html += "<tr style='text-align:center;color:#0099FF;'>";
                                html += "<td style='word-wrap:break-word;word-break:break-all;'>" + (i + 1) + "</td>";
                                html += "<td style='word-wrap:break-word;word-break:break-all;'>" + list[i].kpartMrlcode + "</td>";
                                html += "<td style='word-wrap:break-word;word-break:break-all;'>" + kpartBarcode + "</td>";
                                if (list[i].kpartBindingTime == null || list[i].kpartBindingTime == 'null') {
                                    html += "<td style='word-wrap:break-word;word-break:break-all;'>" + "</td>";
                                } else {
                                    html += "<td style='word-wrap:break-word;word-break:break-all;'>" + list[i].kpartBindingTime + "</td>";
                                }
                                html += "<td>" + "<button style = 'background-color:#46A3FF;color:#FFFFFF; onclick='unbind(\"" + list[i].sysid + "\")'>解绑</button>" + "</td>";
                                html += "</tr>"
                            }
                        }
                        $api.html($api.byId("keyParttbodytable"), html);

                        $("#keyParttableDiv").css('display', 'block');

                    } else {
                        console.log("N");
                        document.getElementById("kpartBarcode").innerHTML = myobj.count;

                        var html = "";

                        scancodeWeb = myobj.barcode;
                        if (scancodeWeb != null && scancodeWeb != '') {
                            // ;text-overflow: ellipsis;white-space:nowrap;overflow: hidden;
                            html += "<tr style='text-align:center;color:#0099FF;'>";
                            html += "<td style='word-wrap:break-word;word-break:break-all;'>" + scancodeWeb + "</td>";
                            html += "<td style='word-wrap:break-word;word-break:break-all;'>" + myobj.mrlname + "</td>";
                            html += "<td style='word-wrap:break-word;word-break:break-all;'>" + myobj.create_date + "</td>";
                            html += "</tr>"

                        }
                        $api.html($api.byId("tbodytable"), html);

                        $("#tableDiv").css('display', 'block');
                        var html = "";
                        if (myobj.list != null && myobj.list != "") {
                            var list = eval(myobj.list);

                            for (var i = 0; i < list.length; i++) {
                                var kpartBarcode = list[i].kpartBarcode == null ? "" : list[i].kpartBarcode;
                                html += "<tr style='text-align:center;color:#0099FF;'>";
                                html += "<td style='word-wrap:break-word;word-break:break-all;'>" + (i + 1) + "</td>";
                                html += "<td style='word-wrap:break-word;word-break:break-all;'>" + list[i].kpartMrlcode + "</td>";
                                html += "<td style='word-wrap:break-word;word-break:break-all;'>" + kpartBarcode + "</td>";
                                if (list[i].kpartBindingTime == null || list[i].kpartBindingTime == 'null') {
                                    html += "<td style='word-wrap:break-word;word-break:break-all;'>" + "</td>";
                                } else {
                                    html += "<td style='word-wrap:break-word;word-break:break-all;'>" + list[i].kpartBindingTime + "</td>";
                                }
                                html += "<td>" + "<button style = 'background-color:#46A3FF;color:#FFFFFF;' onclick='unbind(\"" + list[i].sysid + "\")'>解绑</button>" + "</td>";
                                html += "</tr>"
                            }
                        }
                        $api.html($api.byId("keyParttbodytable"), html);

                        $("#keyParttableDiv").css('display', 'block');

                    }

                    //检测单
                    if (myobj.chkBillList != null && myobj.chkBillList != "") {

                        //检测单明细
                        chkbilldetailsId = myobj.chkBillDetailsId;
                        // createCitemDiv(myobj.chkBillList, myobj.chkBillDetailsId, myobj.chkResult);
                        if (myobj.flagZH === "1") {
                            $("#keyParttableDiv").css('display', 'none');
                            $("#flagZhDiv").css('display', 'block');
                            $("#citemForm").children().remove();
                            $("#citemDiv").css('display', 'none');
                        } else {
                            $("#flagZhDiv").css('display', 'none');
                            createCitemDiv(myobj.chkBillList, myobj.chkBillDetailsId, myobj.chkResult);
                        }
                    } else {
                        $("#flagZhDiv").css('display', 'none');
                        if (myobj.codeType === 'ZC') {
                            chkbilldetailsId = "";
                            $("#citemForm").children().remove();
                            $("#citemDiv").css('display', 'none');

                        }

                    }

                    //查询过点
                    getPassPoint();


                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 6000
                    });

                    //清空人员信息
                    // clear();
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //J解绑关键件
    function unbind(sysid) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/keypartUntie";
        var data = {
            values: {
                relationId: sysid,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    api.toast({
                        msg: "解绑成功!",
                        duration: 1500
                    });
                    doSearch(scancodeWeb, "");
                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            }
        });
    }

    function createCitemDiv(list_D, chkBillDetailsId, chkResult) {

        list = eval(list_D);
        $("#citemForm").children().remove();
        for (var i = 0; i < list.length; i++) {
            var controlType = list[i].controlType; //获取控件类型（0手动输入1多选2单选）
            var citemId = list[i].citemId;
            var citemCode = list[i].citemCode;
            var citemName = list[i].citemName;
            var citemRemark = list[i].citemRemark;
            var labContent = "";
            if (citemRemark != null && citemRemark != "" && citemRemark != undefined) {
                labContent = citemName + "[" + citemRemark + "]";
            } else {
                labContent = citemName;
            }

            var itemId = "citem" + i;

            //定量-手动输入
            if ("0" == controlType) {

                var minValue = list[i].minValue;
                var maxValue = list[i].maxValue;
                var standardValue = list[i].standardValue;
                var chkValue = list[i].chkValue;

                var valContent = "上限值：" + maxValue + " 下限值：" + minValue + " 标准值：" + standardValue;

                labContent = labContent + "[" + valContent + "]";
                var str = "<div class='aui-input-row'>";
                // str += "<p style='width:" + api.frameWidth + "px ;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;text-align: left;color: #000;'>" + labContent + "</p>";
                str += "<p style='width:" + api.frameWidth + "px; text-align: left;color: #000;'>" + labContent + "</p>";
                str += "<div>";
                str += "<input type='number' class='aui-input' placeholder='" + valContent + "' style='' id=\"" + itemId + "\" value='" + chkValue + "' onchange='setChkResult(\"" + minValue + "\",\"" + maxValue +
                    "\",this.id)'/>";
                str += "</div>";
                str += "</div>";
                //手动输入
                $("#citemForm").append(str);

                //定性-多选
            } else if ("1" == controlType) {

                //多选（checkbox）
                var divStr = "<div class='aui-input-row'><p style='width:" + api.frameWidth + "px; text-align:left;color: #000;'>" + labContent +
                    "</p><div class='aui-pull-left' style='width:100%; >";
                var citemDs = eval(list[i].citemDs);
                for (var j = 0; j < citemDs.length; j++) {
                    var citemDId = citemDs[j].id;
                    var citemDCode = citemDs[j].citemDCode;
                    var citemDName = citemDs[j].citemDName;
                    //0待选，1未选，2已选
                    var selectFlag = citemDs[j].selectFlag;
                    //默认选项：1是，2否
                    var isDefault = citemDs[j].isDefault;
                    if (selectFlag == "2") {
                        divStr = divStr + "<input class='aui-checkbox' type='checkbox' name=\"" + itemId + "\" value=\"" + citemDId + "\" checked><div class='aui-checkbox-name'>" + citemDName + "</div>";
                    } else {
                        if (isDefault == "1") {
                            divStr = divStr + "<input class='aui-checkbox' type='checkbox' name=\"" + itemId + "\" value=\"" + citemDId + "\" checked><div class='aui-checkbox-name'>" + citemDName + "</div>";
                        } else {
                            divStr = divStr + "<input class='aui-checkbox' type='checkbox' name=\"" + itemId + "\" value=\"" + citemDId + "\" ><div class='aui-checkbox-name'>" + citemDName + "</div>";
                        }
                    }
                }

                $("#citemForm").append(divStr + "</div></div>");

                //定性-单选
            } else {

                //单选（radio）
                var divStr = "<div class='aui-input-row'><p style='width:" + api.frameWidth + "px; text-align:left;color: #000;'>" + labContent +
                    "</p><div class='aui-pull-left' style='width:100%;' >";
                var citemDs = eval(list[i].citemDs);
                for (var j = 0; j < citemDs.length; j++) {
                    var citemDId = citemDs[j].id;
                    var citemDCode = citemDs[j].citemDCode;
                    var citemDName = citemDs[j].citemDName;


                    //0待选，1未选，2已选
                    var selectFlag = citemDs[j].selectFlag;
                    //默认选项：1是，2否
                    var isDefault = citemDs[j].isDefault;

                    if (selectFlag == "2") {
                        divStr = divStr + "<input class='aui-radio' type='radio' name=\"" + itemId + "\" value=\"" + citemDId + "\" checked><div class='aui-radio-name'>" + citemDName + "</div>";
                    } else {
                        if (isDefault == "1") {
                            divStr = divStr + "<input class='aui-radio' type='radio' name=\"" + itemId + "\" value=\"" + citemDId + "\" checked><div class='aui-radio-name'>" + citemDName + "</div>";
                        } else {
                            divStr = divStr + "<input class='aui-radio' type='radio' name=\"" + itemId + "\" value=\"" + citemDId + "\"><div class='aui-radio-name'>" + citemDName + "</div>";
                        }
                    }
                }

                $("#citemForm").append(divStr + "</div></div>");
            }
        }

        //检测结果不为0（未判定），显示
        if (chkResult != "0") {
            var chkResultStr = "<div class='aui-input-row'>";
            if (chkResult == "1") {
                chkResultStr += "<p style='width:" + api.frameWidth + "px; text-align: center;color: white;'><span style = 'font-size:25px;background-color:red'> 判定结果：不合格</span></p>";
            } else if (chkResult == "5") {
                chkResultStr += "<p style='width:" + api.frameWidth + "px; text-align: left;color: #000;'>判定结果：放行</p>";
            } else {
                chkResultStr += "<p style='width:" + api.frameWidth + "px; text-align: center;color: white;'><span style = 'font-size:25px;background-color:green'>判定结果：合格</span></p>";
            }
            chkResultStr += "</div>";
            $("#citemForm").append(chkResultStr);
        }
        if (scanQualifiedCode == "") {
            $("#citemForm").append("<br /><div class='aui-btn aui-btn-info' style='width:40%;margin-left:7%' onclick='doSaveChkResult(7,\"" + chkBillDetailsId + "\" )'>合格</div>");
            $("#citemForm").append("<div class='aui-btn aui-btn-info' style='width:40%;margin-left:6%' onclick='doSaveChkResult(1,\"" + chkBillDetailsId + "\")'>不合格</div>");
        }
        $("#citemDiv").css('display', 'block');
    }

    //比较检测值
    function setChkResult(minValue, maxValue, id) {

    }

    //查询检测结果
    function doSaveChkResult(chkResult, chkBillDetailsId) {
        var josnList = [];
        for (var i = 0; i < list.length; i++) {

            //获取控件类型（0手动输入1多选2单选）
            var controlType = list[i].controlType;
            var itemId = "citem" + i;
            var itemValue = "";

            //手动输入
            if ("0" == list[i].controlType) {

                itemValue = document.getElementById(itemId).value;

                //多选
            } else if ("1" == list[i].controlType) {

                var checkBoxObj = document.getElementsByName(itemId); //这个是以标签的name来取控件
                for (m = 0; m < checkBoxObj.length; m++) {
                    if (checkBoxObj[m].checked) {
                        itemValue = itemValue + checkBoxObj[m].value + ",";
                    }
                }
                if (checkBoxObj.length > 0) {
                    //有选中，则最后一个需要去掉“,”
                    itemValue = itemValue.substring(0, itemValue.length - 1);
                }

                //单选
            } else {
                var radioObj = document.getElementsByName(itemId); //这个是以标签的name来取控件
                for (n = 0; n < radioObj.length; n++) {
                    if (radioObj[n].checked) {
                        itemValue = radioObj[n].value;
                    }
                }
            }

            josnList.push({
                "chkBillId": list[i].id,
                "chkResult": itemValue
            });
        }
        var res = chkResult == 1 ? "N" : "Y";

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/qualifiedSave";
        var data = {
            values: {
                chkBillDetailsId: chkBillDetailsId, //检测单明细id
                chkResult: res, //检测单明细检测项结果
                rowData: JSON.stringify(josnList),
                un: un,
                opCode: opCode,
                scanCode: scancodeWeb,
                flag: res,
                workCellCode: workCellCode,
                equipUniqueCode: equipUniqueId,
                lineCode: workCenterCode,
                operator: empName
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    $("#boxnum").focus();
                    //刷新检测单
                    getChkBill();

                    if (chkResult == 1) {
                        // toNoConformProduct()
                        alert('该件不合格，请联系质检人员处理！')
                    }

                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                alert("连接超时，请耐心等待");
            }
        });
    }

    //缺陷内容下拉选
    function toNoConformProduct() {
        if (AirTightness != '') {
            api.openWin({
                name: 'nonConformProductByNew',
                url: 'nonConformProductByNew.html',
                pageParam: {
                    // code: type,
                    // name: "nonConformProduct",
                    barcode: scancodeWeb,
                    opCode: opCode,
                    equipUniqueId: equipUniqueId,
                    shiftCode: shiftCode,
                    name: "paScanBarcodeNew",
                }
            });
        } else {
            api.openWin({
                name: 'nonConformProduct',
                url: 'nonConformProduct.html',
                pageParam: {
                    // code: type,
                    // name: "nonConformProduct",
                    barcode: scancodeWeb,
                    opCode: opCode,
                    equipUniqueId: equipUniqueId,
                    shiftCode: shiftCode,
                    name: "paScanBarcodeNew",
                }
            });
        }


    }

    //查询检测结果
    function doSaveChkResult1(chkResult, chkBillDetailsId) {
        var josnList = [];
        for (var i = 0; i < list.length; i++) {

            //获取控件类型（0手动输入1多选2单选）
            var controlType = list[i].controlType;
            var itemId = "citem" + i;
            var itemValue = "";

            //手动输入
            if ("0" == list[i].controlType) {

                itemValue = document.getElementById(itemId).value;

                //多选
            } else if ("1" == list[i].controlType) {

                var checkBoxObj = document.getElementsByName(itemId); //这个是以标签的name来取控件
                for (m = 0; m < checkBoxObj.length; m++) {
                    if (checkBoxObj[m].checked) {
                        itemValue = itemValue + checkBoxObj[m].value + ",";
                    }
                }
                if (checkBoxObj.length > 0) {
                    //有选中，则最后一个需要去掉“,”
                    itemValue = itemValue.substring(0, itemValue.length - 1);
                }

                //单选
            } else {
                var radioObj = document.getElementsByName(itemId); //这个是以标签的name来取控件
                for (n = 0; n < radioObj.length; n++) {
                    if (radioObj[n].checked) {
                        itemValue = radioObj[n].value;
                    }
                }
            }

            josnList.push({
                "id": list[i].id,
                "chkValue": itemValue
            });
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/saveUqcmChkBillDetail";
        var data = {
            values: {
                chkBillDetailsId: chkBillDetailsId, //检测单明细id
                chkResult: chkResult, //检测单明细检测项结果
                josnList: JSON.stringify(josnList),
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {


                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            }
        });
    }

    //扫描之后条码解析
    function tmSplit(sm) {

        var arr = sm.split(",");

        if (arr.length == 1) {
            $("#boxnum").val(sm);
            doSearch();
        } else {
            //直接解析
            if (scanRule == "old") {

                //本地解析
                localAnalyze(sm);

            } else {

                //后台解析
                postAnalyze(sm);
            }
        }
    }

    //本地解析
    function localAnalyze(sm) {
        var arr = sm.split(",");
        if (arr[9] == null || arr[9] == undefined) {
            $("#boxnum").val("");
        } else {
            $("#boxnum").val(arr[9]);
        }
        doSearch();

    }

    //后台解析条码
    function postAnalyze(sm) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/analysisBarCodeCommon";
        var data = {
            values: {
                tm: sm, //条码
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    var map = myobj.data;
                    $("#boxnum").val(map["boxnum"]);
                    //自动保存
                    doSearch();
                } else if (myobj.code == '1') {

                    $("#boxnum").val("");
                    $("#boxnum").select();
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    //构造传参map
    function createPageParam() {
        pageParam = {
            workCenterCode: workCenterCode,
            workCellCode: workCellCode,
            opCode: opCode,
            ruleCode: ruleCode,
            teamCode: teamCode,
            teamName: teamName,
            shiftCode: shiftCode,
            shiftName: shiftName,
            proddate: proddate,
            rootName: "paScanBarcodeNew",
            name: "paScanBarcodeNew",
            sgFlag: '0',//上岗标识：0刷卡，1勾选
            isCheckPersonnelSkill: isCheckPersonnelSkill
        }
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            $("#boxnum").val(ret);
            doSearch();
        });
    }

    //查询检测单
    function getChkBill() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getCitemsByDetailId";
        var data = {
            values: {
                chkBillDetailsId: chkbilldetailsId, //检测单明细id
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == 0) {

                    createCitemDiv(myobj.chkBillList, chkbilldetailsId, myobj.chkResult);

                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //清空人员上岗信息
    function clear() {
        $("#empName").val("")
        teamCode = "";
        teamName = "";
        shiftCode = "";
        shiftName = "";
        proddate = "";
    }

    //查询数据
    function refresh() {

        //1:查询当前操作人员信息
        searchDutyPersonData();

        //查询过点
        getPassPoint();
    }

    //不合格返回刷新
    function refreshData() {

        //查询过点
        getPassPoint();

        if (chkbilldetailsId != null && chkbilldetailsId != "" && chkbilldetailsId != undefined) {
            //查询检测单
            getChkBill();
        }
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>